/**
 * @Author: cest
 * @Date: 2022-08-04 10:09:30
 * @LastEditTime: 2022-08-04 16:34:46
 * @LastEditors: cest
 * @FilePath: /vue3-todo-list/src/hooks/useMapper.js
 * @Description: 编辑描述内容
 */
import { useStore } from 'vuex';
import { computed } from 'vue';

export const mapper = (mapArry, mapFn) => {
  const store = useStore()
  const stateStoreFn = mapFn(mapArry)
  const stateStore = {}
  Object.keys(stateStoreFn).forEach(item => {
    const fn = stateStoreFn[item].bind({ $store: store })
    stateStore[item] = computed(fn)
  })
  return stateStore
}

export const mapHelper = (namespaced, pMapper) => (namespaced ? `${namespaced}/${pMapper}` : pMapper)

export default mapper
